package o;

import android.content.Context;
import com.huawei.appgallery.forum.base.card.bean.ImageInfo;
import com.huawei.appgallery.forum.base.card.bean.Post;
import com.huawei.appgallery.forum.base.card.bean.PostTime;
import com.huawei.appgallery.forum.base.card.bean.SortInfo;
import com.huawei.appgallery.forum.base.card.bean.User;
import com.huawei.appgallery.forum.cards.bean.ForumTitleSortCardBean;
import com.huawei.appgallery.forum.cards.node.BuoyForumTitleSortNode;
import com.huawei.appgallery.forum.cards.node.ForumTitleSortNode;
import com.huawei.appgallery.forum.posts.card.BuoyForumTopicCommentNode;
import com.huawei.appgallery.forum.posts.card.ForumTopicCommentCardBean;
import com.huawei.appgallery.forum.posts.card.ForumTopicCommentNode;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import java.util.ArrayList;
import java.util.List;
import o.bzd.j;

public class bzn extends brv {
    private Long ˋ;
    private Long ˏ;

    public bzn(Context context) {
        super(context);
    }

    public chz ˋ(long j, int i, int i2, List<CardBean> list) {
        bqx.ˏ("PostDetailDataProvider", "addCardChunk, id:" + j + ", cardType:" + i);
        chz ˋ = super.ˋ(j, i, i2, list);
        if (ˋ != null) {
            if (ˋ.ˋ instanceof ForumTopicCommentNode) {
                this.ˋ = Long.valueOf(j);
            } else if (ˋ.ˋ instanceof BuoyForumTopicCommentNode) {
                this.ˋ = Long.valueOf(j);
            }
            if (ˋ.ˋ instanceof ForumTitleSortNode) {
                this.ˏ = Long.valueOf(j);
            } else if (ˋ.ˋ instanceof BuoyForumTitleSortNode) {
                this.ˏ = Long.valueOf(j);
            }
        }
        return ˋ;
    }

    public void ˊ() {
        chz ॱ = ॱ(this.ˏ.longValue());
        if (CollectCheck.isEmpty(ॱ.ˏ())) {
            ForumTitleSortCardBean forumTitleSortCardBean = new ForumTitleSortCardBean();
            forumTitleSortCardBean.ˏ(bqy.ˋ().ˏ().getString(j.ˊˋ));
            SortInfo sortInfo = new SortInfo();
            sortInfo.ˏ(0);
            sortInfo.ˎ("asc");
            sortInfo.ॱ(bqy.ˋ().ˏ().getString(j.ʼॱ));
            SortInfo sortInfo2 = new SortInfo();
            sortInfo2.ˏ(1);
            sortInfo2.ˎ("desc");
            sortInfo2.ॱ(bqy.ˋ().ˏ().getString(j.ˈ));
            List arrayList = new ArrayList();
            arrayList.add(sortInfo);
            arrayList.add(sortInfo2);
            forumTitleSortCardBean.ˊ(arrayList);
            List arrayList2 = new ArrayList();
            arrayList2.add(forumTitleSortCardBean);
            ॱ.ˊ(arrayList2);
        }
        ॱ = ॱ(this.ˋ.longValue());
        if (CollectCheck.isEmpty(ॱ.ˏ())) {
            ForumTopicCommentCardBean forumTopicCommentCardBean = new ForumTopicCommentCardBean(true);
            arrayList2 = new ArrayList();
            arrayList2.add(forumTopicCommentCardBean);
            ॱ.ˊ(arrayList2);
        }
        ͺ();
    }

    public int ˊ(User user, byg o_byg, String str, int i) {
        int i2 = 0;
        if (!(this.ˋ == null || o_byg == null)) {
            Post post = new Post();
            post.ˏ(o_byg.ˊ());
            post.ˊ(o_byg.ˏ());
            PostTime postTime = new PostTime();
            postTime.ॱ(String.valueOf(System.currentTimeMillis()));
            postTime.ˊ(String.valueOf(System.currentTimeMillis()));
            post.ˏ(postTime);
            post.ˎ("forum|post_detail|" + post.ˏ());
            post.ॱ(0);
            byl ॱ = o_byg.ॱ();
            if (ॱ != null) {
                ImageInfo imageInfo = new ImageInfo();
                imageInfo.ˏ(ॱ.ʽ());
                imageInfo.ˊ(ॱ.ʽ());
                imageInfo.ˊ(ॱ.ˏॱ());
                imageInfo.ˋ(ॱ.ͺ() + "_" + ॱ.ॱˊ());
                List arrayList = new ArrayList();
                arrayList.add(imageInfo);
                post.ˏ(arrayList);
            }
            post.ˏ(2);
            ForumTopicCommentCardBean forumTopicCommentCardBean = new ForumTopicCommentCardBean(user, post, 0, null, 0, str, i);
            for (chz ˏ : this.ॱॱ) {
                if (!CollectCheck.isEmpty(ˏ.ˏ())) {
                    i2++;
                }
            }
            chz ˏ2 = ॱ(this.ˋ.longValue());
            List<CardBean> ˏ3 = ˏ2.ˏ();
            List arrayList2 = new ArrayList();
            arrayList2.add(forumTopicCommentCardBean);
            if (!CollectCheck.isEmpty((List) ˏ3)) {
                for (CardBean cardBean : ˏ3) {
                    if (cardBean instanceof ForumTopicCommentCardBean) {
                        forumTopicCommentCardBean = (ForumTopicCommentCardBean) cardBean;
                        if (!forumTopicCommentCardBean.ˏॱ()) {
                            arrayList2.add(forumTopicCommentCardBean);
                        }
                    }
                }
            }
            ˏ2.ˊ(arrayList2);
        }
        bqx.ˏ("PostDetailDataProvider", "CommentNodePosition:" + i2);
        return i2 <= 2 ? i2 : i2 - 1;
    }

    public void ॱ(long j, boolean z) {
        for (chz o_chz : ʻॱ()) {
            Object obj;
            if (z ? (o_chz.ˋ instanceof BuoyForumTopicCommentNode) : (o_chz.ˋ instanceof ForumTopicCommentNode)) {
                List<CardBean> ˏ = o_chz.ˏ();
                if (!CollectCheck.isEmpty((List) ˏ)) {
                    List arrayList = new ArrayList();
                    for (CardBean cardBean : ˏ) {
                        if (cardBean instanceof ForumTopicCommentCardBean) {
                            ForumTopicCommentCardBean forumTopicCommentCardBean = (ForumTopicCommentCardBean) cardBean;
                            if (!(forumTopicCommentCardBean.ˏॱ() || forumTopicCommentCardBean.ʼ().ˏ() == j)) {
                                arrayList.add(cardBean);
                            }
                        }
                    }
                    o_chz.ˊ(arrayList);
                    if (CollectCheck.isEmpty(arrayList)) {
                        int i = 1;
                    } else {
                        obj = null;
                    }
                    if (obj != null) {
                        ˊ();
                    }
                }
            }
            obj = 1;
            if (obj != null) {
                ˊ();
            }
        }
    }

    public void ˏ(long j) {
        ॱ(j, false);
    }
}
